<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 将句子排序 -->
    <script>
      var sortSentence = function (s) {
        let a = s.split(' ')
        let res = []
        for (let i = 0; i < a.length; i++) {
          // 取元素该放的位置
          let index = a[i].slice(-1)
          // 取对应位置的值
          let temp = a[i].slice(0, a[i].length - 1)
          res[index - 1] = temp
        }
        return res.join(' ')
      }
      console.log(sortSentence('is2 sentence4 This1 a3'))
    </script>
  </body>
</html>
